﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace game
{
    public class PlayerFighter : Fighter
    {
        public PlayerFighter(Scene scene, ModelUnit model, int layerIndex, Vector3 position, Squadron squadron)
            : base(scene, model, layerIndex, position, squadron)
        {
            Health = 150.0f;
            MaxHealth = Health;
            ActiveWeaponIndex = 0;

            traceHandler.AddTraceSource(new Vector3(1430.0f, 50.0f, 600.0f));
            traceHandler.AddTraceSource(new Vector3(-1430.0f, 50.0f, 600.0f));
            //traceHandler.AddTraceSource(new Vector3(0.0f, 50.0f, -1150.0f));
            //traceHandler.AddTraceSource(new Vector3(-500.0f, 500.0f, 0.0f));
        }

        public override void Update(GameTime gameTime)
        {
            Target = scene.Layers[LayerIndex].GetClosestEnemy(this);
            base.Update(gameTime);
            CheckInput(gameTime);
        }

        public override void Collision(GameObject obj)
        {
            base.Collision(obj);
            scene.ActiveCamera.Shake(0.005f * obj.GetDamage());
        }

        protected void CheckInput(GameTime gameTime)
        {

            if (Input.Keyboard.IsKeyDown(Keys.Up))
            {
                SpeedUp();
            }
            if (Input.Keyboard.IsKeyDown(Keys.Down))
            {
                SlowDown();
            }


            if (!flyingDown)
            {
                if (Input.Keyboard.IsKeyDown(Keys.Left))
                {
                    LeanLeft();
                }
                if (Input.Keyboard.IsKeyDown(Keys.Right))
                {
                    LeanRight();
                }
            }


            if (Input.Keyboard.IsKeyDown(Keys.Space))
            {
                ShootWeapon();
            }

            if (Input.Keyboard.IsKeyDown(Keys.LeftShift))
            {
                ShootRocket();
            }

            if (Input.Keyboard.IsKeyDown(Keys.Q))
            {
                CycleWeaponLeft();
            }

            if (Input.Keyboard.IsKeyDown(Keys.E))
            {
                CycleWeaponRight();
            }

            if (Input.Keyboard.IsKeyDown(Keys.S))
            {
                FlyDown();
            }

            if (Input.Keyboard.IsKeyDown(Keys.W))
            {
                FlyUp();
            }

            if (Input.Keyboard.IsKeyDown(Keys.A))
            {
               DodgeLeft();
            }

            if (Input.Keyboard.IsKeyDown(Keys.D))
            {
               DodgeRight();
            }

            if (Input.Keyboard.IsKeyDown(Keys.R))
            {
                TurnOnShield();
            }

        }
    }
}
